<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: DatfileController</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">DatfileController</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/app/controllers/datfile_controller_rb.html">
                app/controllers/datfile_controller.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="ApplicationController.html">
                ApplicationController
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000010">changeone</a>&nbsp;&nbsp;
      <a href="#M000012">getString</a>&nbsp;&nbsp;
      <a href="#M000011">getdone</a>&nbsp;&nbsp;
      <a href="#M000009">make</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000010" class="method-detail">
        <a name="M000010"></a>

        <div class="method-heading">
          <a href="#M000010" class="method-signature">
          <span class="method-name">changeone</span><span class="method-args">(ip,i)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000010-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/datfile_controller.rb, line 45</span>
45:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">changeone</span>(<span class="ruby-identifier">ip</span>,<span class="ruby-identifier">i</span>)
46:    <span class="ruby-identifier">parts</span> = <span class="ruby-identifier">ip</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;[.]&quot;</span>)
47:    <span class="ruby-identifier">int_array</span>=<span class="ruby-constant">RangeMark</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">ip</span>).<span class="ruby-identifier">getTokens</span>
48:    <span class="ruby-identifier">int_new</span>=<span class="ruby-identifier">getdone</span>(<span class="ruby-identifier">int_array</span>,<span class="ruby-value">3</span>,<span class="ruby-identifier">i</span>)
49:    <span class="ruby-identifier">int_new</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">'.'</span>)
50:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000012" class="method-detail">
        <a name="M000012"></a>

        <div class="method-heading">
          <a href="#M000012" class="method-signature">
          <span class="method-name">getString</span><span class="method-args">(addresses)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000012-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/datfile_controller.rb, line 72</span>
72:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getString</span>(<span class="ruby-identifier">addresses</span>)
73:   <span class="ruby-identifier">string</span>=<span class="ruby-constant">String</span>.<span class="ruby-identifier">new</span>
74:   <span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span><span class="ruby-operator">|</span><span class="ruby-identifier">string</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">startpoint</span>.<span class="ruby-identifier">ip</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;-&quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">a</span>.<span class="ruby-identifier">endpoint</span>.<span class="ruby-identifier">ip</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;,200,for ban ips\n&quot;</span>}
75: 
76:   <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">string</span>.<span class="ruby-identifier">chomp</span>
77:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000011" class="method-detail">
        <a name="M000011"></a>

        <div class="method-heading">
          <a href="#M000011" class="method-signature">
          <span class="method-name">getdone</span><span class="method-args">(i,x,add)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000011-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/datfile_controller.rb, line 51</span>
51:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">getdone</span>(<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span>,<span class="ruby-identifier">add</span>)
52:   <span class="ruby-identifier">puts</span> <span class="ruby-identifier">i</span>.<span class="ruby-identifier">length</span>,<span class="ruby-identifier">x</span>,<span class="ruby-identifier">add</span>
53:     <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">add</span><span class="ruby-operator">==</span><span class="ruby-value">1</span>)
54:     <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>]<span class="ruby-operator">==</span><span class="ruby-value">255</span>)
55:       <span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>]=<span class="ruby-value">0</span>
56:       <span class="ruby-identifier">getdone</span>(<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>,<span class="ruby-value">1</span>)
57:     <span class="ruby-keyword kw">end</span>
58:     
59:     <span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>] <span class="ruby-operator">+=</span><span class="ruby-value">1</span>
60:    <span class="ruby-keyword kw">end</span>
61:         
62:    <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">add</span><span class="ruby-operator">==</span><span class="ruby-value">-1</span>)
63:      <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>]<span class="ruby-operator">==</span><span class="ruby-value">0</span>)
64:          <span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>]=<span class="ruby-value">255</span>
65:         <span class="ruby-identifier">getdone</span>(<span class="ruby-identifier">i</span>,<span class="ruby-identifier">x</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>,<span class="ruby-value">-1</span>)
66:      <span class="ruby-keyword kw">end</span>
67:      <span class="ruby-identifier">i</span>[<span class="ruby-identifier">x</span>]<span class="ruby-operator">-=</span><span class="ruby-value">1</span>
68:     <span class="ruby-keyword kw">end</span>
69:        <span class="ruby-identifier">i</span>
70:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000009" class="method-detail">
        <a name="M000009"></a>

        <div class="method-heading">
          <a href="#M000009" class="method-signature">
          <span class="method-name">make</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000009-source">
<pre>
    <span class="ruby-comment cmt"># File app/controllers/datfile_controller.rb, line 3</span>
 3:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">make</span>
 4:   
 5:   <span class="ruby-identifier">s</span>=<span class="ruby-constant">Swarm</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span>[<span class="ruby-value str">&quot;url = :url&quot;</span>,{<span class="ruby-identifier">:url=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">params</span>[<span class="ruby-identifier">:swarm_url</span>]}])
 6:   <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">s</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">:controller=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;index&quot;</span> <span class="ruby-keyword kw">end</span>
 7:   <span class="ruby-identifier">ucs</span>=<span class="ruby-constant">UserConnection</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span>[<span class="ruby-value str">&quot;swarm_id =:swarm_id and thetime &gt; :time&quot;</span>,{<span class="ruby-identifier">:swarm_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">s</span>.<span class="ruby-identifier">id</span>,<span class="ruby-identifier">:time=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">6</span>.<span class="ruby-identifier">minutes</span>.<span class="ruby-identifier">ago</span>}],<span class="ruby-identifier">:group=</span><span class="ruby-operator">&gt;</span><span class="ruby-value str">&quot;ip&quot;</span>)
 8:   <span class="ruby-identifier">addresses</span>=<span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
 9:   <span class="ruby-identifier">addresses_new</span>=<span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
10:   <span class="ruby-identifier">addresses</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">InetAddressRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;0.0.0.0&quot;</span>,<span class="ruby-value str">&quot;9.255.255.255&quot;</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">InetAddressRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;11.0.0.0&quot;</span>,<span class="ruby-value str">&quot;192.167.255.255&quot;</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">InetAddressRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;192.169.0.0&quot;</span>,<span class="ruby-value str">&quot;255.255.255.255&quot;</span>)
11:   <span class="ruby-identifier">ucs</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">u</span><span class="ruby-operator">|</span><span class="ruby-identifier">u</span>.<span class="ruby-identifier">ip</span>
12:  
13:   <span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">each_index</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">addr</span><span class="ruby-operator">|</span>
14:  
15:   <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">addresses</span>[<span class="ruby-identifier">addr</span>].<span class="ruby-identifier">isInRange</span>(<span class="ruby-identifier">u</span>.<span class="ruby-identifier">ip</span>))
16:   <span class="ruby-identifier">puts</span> <span class="ruby-identifier">u</span>.<span class="ruby-identifier">ip</span>
17:   <span class="ruby-identifier">addresses_new</span> = <span class="ruby-identifier">addresses</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span>(<span class="ruby-identifier">addr</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)]<span class="ruby-operator">+</span> 
18:   [ <span class="ruby-constant">InetAddressRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">addresses</span>[<span class="ruby-identifier">addr</span>].<span class="ruby-identifier">startpoint</span>.<span class="ruby-identifier">ip</span>,<span class="ruby-identifier">changeone</span>(<span class="ruby-identifier">u</span>.<span class="ruby-identifier">ip</span>,<span class="ruby-value">-1</span>)),<span class="ruby-constant">InetAddressRange</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">changeone</span>(<span class="ruby-identifier">u</span>.<span class="ruby-identifier">ip</span>,<span class="ruby-value">1</span>),<span class="ruby-identifier">addresses</span>[<span class="ruby-identifier">addr</span>].<span class="ruby-identifier">endpoint</span>.<span class="ruby-identifier">ip</span>)]<span class="ruby-operator">+</span>
19:   <span class="ruby-identifier">addresses</span>[<span class="ruby-identifier">addr</span><span class="ruby-operator">+</span><span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">addresses</span>.<span class="ruby-identifier">length</span>]
20:   <span class="ruby-identifier">addresses</span>=<span class="ruby-identifier">addresses_new</span>
21:   <span class="ruby-keyword kw">break</span>
22:   <span class="ruby-keyword kw">end</span>
23:   
24:    }
25:   
26:   }
27:   
28: 
29:   <span class="ruby-ivar">@content</span>=<span class="ruby-identifier">getString</span>(<span class="ruby-identifier">addresses</span>);
30:   
31: <span class="ruby-keyword kw">if</span>(<span class="ruby-identifier">session</span>[<span class="ruby-identifier">:user</span>].<span class="ruby-identifier">nil?</span>)<span class="ruby-keyword kw">then</span> <span class="ruby-identifier">user_id</span> = <span class="ruby-value">0</span> <span class="ruby-keyword kw">end</span>
32: <span class="ruby-identifier">uc2</span>=<span class="ruby-constant">UserConnection</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:first</span>,<span class="ruby-identifier">:conditions=</span><span class="ruby-operator">&gt;</span>[<span class="ruby-value str">&quot;user_id = :user_id and swarm_id =:swarm_id and ip=:ip and thetime &gt; :thetime&quot;</span>,{<span class="ruby-identifier">:swarm_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">s</span>.<span class="ruby-identifier">id</span>,<span class="ruby-identifier">:ip=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">request</span>.<span class="ruby-identifier">remote_ip</span>,<span class="ruby-identifier">:user_id=</span><span class="ruby-operator">&gt;</span><span class="ruby-identifier">user_id</span>,<span class="ruby-identifier">:thetime=</span><span class="ruby-operator">&gt;</span><span class="ruby-value">3</span>.<span class="ruby-identifier">minutes</span>.<span class="ruby-identifier">ago</span>}])
33: <span class="ruby-keyword kw">if</span>(<span class="ruby-operator">!</span><span class="ruby-identifier">uc2</span>.<span class="ruby-identifier">nil?</span>)<span class="ruby-keyword kw">then</span> <span class="ruby-identifier">uc2</span>.<span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">:thetime=</span><span class="ruby-operator">&gt;</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>) <span class="ruby-keyword kw">end</span>
34: 
35:  
36:   <span class="ruby-ivar">@content_type</span>=<span class="ruby-value str">'text/plain'</span>
37:   <span class="ruby-ivar">@response</span>.<span class="ruby-identifier">headers</span>[<span class="ruby-value str">&quot;Content-Type&quot;</span>] = <span class="ruby-ivar">@content_type</span>
38:    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span>(<span class="ruby-value str">&quot;request.remote_ip =&gt; &quot;</span><span class="ruby-operator">+</span><span class="ruby-identifier">request</span>.<span class="ruby-identifier">remote_ip</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;time=&gt;&quot;</span><span class="ruby-operator">+</span><span class="ruby-constant">Time</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">to_s</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;vincent messege dat=&gt;\n&quot;</span><span class="ruby-operator">+</span><span class="ruby-ivar">@content</span><span class="ruby-operator">+</span><span class="ruby-value str">&quot;\n end vicent messege&quot;</span>)
39:   <span class="ruby-identifier">render</span> <span class="ruby-identifier">:layout=</span><span class="ruby-operator">&gt;</span><span class="ruby-keyword kw">false</span>
40: 
41:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>